import request from '@/utils/request'

let VITE_APP_BASE_API = localStorage.getItem("local_server_ip") || window.HC_config.VITE_APP_BASE_API || process.env.VITE_APP_BASE_API;

const api = {
    basepath: '/gwfj/word-files'
}

export function saveWordFiles(parameter) {
    return request({
        url: api.basepath,
        method: 'post',
        data: parameter,
        headers: {
            'Content-Type': 'application/json;charset=UTF-8'
        }
    })
}

export function delWordFiles(parameter) {
    return request({
        url: api.basepath,
        method: 'Delete',
        params: parameter
    })
}

export function downWordFile(id) {
    return request({
        url: api.basepath + '/' + id,
        method: 'get'
    })
}

export function getList(parameter) {
    return request({
        url: api.basepath + '/list',
        method: 'get',
        params: parameter
    })
}

export function getInfo(unid) {
    return request({
        url: api.basepath + '/' + unid,
        method: 'get'
    })
}
// 获取下载url
export function getDownloadUrl(unid) {
    console.log(VITE_APP_BASE_API + '/gwfj/word-files/download/' + unid)
    return VITE_APP_BASE_API + '/gwfj/word-files/download/' + unid
}

// 获取下载url
export function getDownloadZBUrl(unid) {
    console.log(VITE_APP_BASE_API + '/gwfj/word-files/downloadZB/' + unid)
    return VITE_APP_BASE_API + '/gwfj/word-files/downloadZB/' + unid
}

// 上传正文
export function openUploadzw(unid, name, formData, callback) {
    return request({
        url: api.basepath + '/upload/' + unid + '/' + name,
        method: 'post',
        data: formData,
        timeout: 10000000,
        onUploadProgress(progressEvent) {
            if (progressEvent.lengthComputable) {
                const val = (progressEvent.loaded / progressEvent.total * 100).toFixed(0)
                var progress = parseInt(val)
                callback(progress)
            }
        }
    })
}

// 上传正文
export function openUploadZB(parentunid, formData, callback) {
    return request({
        url: api.basepath + '/uploadMakedWordFile/' + parentunid,
        method: 'post',
        data: formData,
        headers:{
            'Content-Type':'multipart/form-data'
        },
        timeout: 10000000,
        onUploadProgress(progressEvent) {
            if (progressEvent.lengthComputable) {
                const val = (progressEvent.loaded / progressEvent.total * 100).toFixed(0)
                var progress = parseInt(val)
                callback(progress)
            }
        }
    })
}